package com.jackiechancinema.ssm.service.Impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.jackiechancinema.ssm.config.SystemContant;
import com.jackiechancinema.ssm.dao.FilmPerfDao;
import com.jackiechancinema.ssm.entity.FilmPerf;
import com.jackiechancinema.ssm.service.Inte.FilmPerfService;
import com.jackiechancinema.ssm.vo.PageVo;
import com.jackiechancinema.ssm.vo.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

@Repository
public class FilmPerfServiceImpl implements FilmPerfService {
    @Autowired
    private FilmPerfDao filmPerfDao;
    @Override
    public PageVo<FilmPerf> queryAll(int page, int limit) {
        //1.开启分页插件
        PageHelper.startPage(page, limit);
        PageInfo<FilmPerf> pageInfo=new PageInfo<FilmPerf>(filmPerfDao.queryAll());
        return new PageVo<FilmPerf>(SystemContant.PAGE_R,"OK",pageInfo.getTotal(),pageInfo.getList());
    }

    @Override
    public R insert(FilmPerf filmPerf) {
        R r = new R();
        if(filmPerfDao.insert(filmPerf)>0){
            r.setCode(SystemContant.R_OK);
            r.setMsg("添加成功");
        }else{
            r.setCode(SystemContant.R_FAIL);
            r.setMsg("添加失败");
        }
        return r;
    }

    @Override
    public R updete(FilmPerf filmPerf) {
        R r = new R();
        if(filmPerfDao.update(filmPerf)>0){
            r.setCode(SystemContant.R_OK);
            r.setMsg("更改成功");
        }else{
            r.setCode(SystemContant.R_FAIL);
            r.setMsg("更改失败");
        }
        return r;
    }

    @Override
    public R delete(int filmperf_id) {
        R r = new R();
        if(filmPerfDao.delete(filmperf_id)>0){
            r.setCode(SystemContant.R_OK);
            r.setMsg("删除成功");
        }else{
            r.setCode(SystemContant.R_FAIL);
            r.setMsg("删除失败");
        }
        return r;
    }
}
